{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 22,
   "id": "9cd995d3",
   "metadata": {},
   "outputs": [],
   "source": [
    "from datetime import datetime\n",
    "import cProfile\n",
    "\n",
    "from vnpy.app.cta_strategy.backtesting import BacktestingEngine, OptimizationSetting\n",
    "from vnpy.app.cta_strategy.strategies.atr_rsi_strategy import AtrRsiStrategy"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 23,
   "id": "1e789d06",
   "metadata": {},
   "outputs": [],
   "source": [
    "def runBacktesting():\n",
    "    engine = BacktestingEngine()\n",
    "    engine.set_parameters(\n",
    "        vt_symbol=\"I2109.DCE\",\n",
    "        interval=\"1m\",\n",
    "        start=datetime(2021, 6, 1),\n",
    "        end=datetime(2021, 9, 27),\n",
    "        rate=0.3/10000,\n",
    "        slippage=0.2,\n",
    "        size=300,\n",
    "        pricetick=0.2,\n",
    "        capital=1_000_000,\n",
    "    )\n",
    "    engine.add_strategy(AtrRsiStrategy, {})\n",
    "    engine.load_data()\n",
    "    engine.run_backtesting()\n",
    "    engine.calculate_result()\n",
    "    engine.calculate_statistics()\n",
    "    engine.show_chart()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 24,
   "id": "f3e732bb",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "2021-12-30 19:44:28.795385\t开始加载历史数据\n",
      "2021-12-30 19:44:28.795385\t加载进度：# [0%]\n",
      "2021-12-30 19:44:29.102340\t加载进度：# [9%]\n",
      "2021-12-30 19:44:29.272004\t加载进度：## [19%]\n",
      "2021-12-30 19:44:29.488627\t加载进度：### [28%]\n",
      "2021-12-30 19:44:29.732675\t加载进度：#### [37%]\n",
      "2021-12-30 19:44:29.920740\t加载进度：##### [47%]\n",
      "2021-12-30 19:44:30.503929\t加载进度：###### [56%]\n",
      "2021-12-30 19:44:30.693611\t加载进度：####### [65%]\n",
      "2021-12-30 19:44:30.927837\t加载进度：######## [75%]\n",
      "2021-12-30 19:44:31.128232\t加载进度：######### [84%]\n"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "2021-12-30 19:44:31,273  INFO: None\t策略初始化\n",
      "2021-12-30 19:44:31,273  INFO: None\t策略初始化\n",
      "2021-12-30 19:44:31,273  INFO: None\t策略初始化\n",
      "2021-12-30 19:44:31,273  INFO: None\t策略初始化\n",
      "2021-12-30 19:44:31,273  INFO: None\t策略初始化\n",
      "2021-12-30 19:44:31,273  INFO: None\t策略初始化\n",
      "2021-12-30 19:44:31,273  INFO: None\t策略初始化\n",
      "2021-12-30 19:44:31,273  INFO: None\t策略初始化\n",
      "2021-12-30 19:44:31,273  INFO: None\t策略初始化\n",
      "2021-12-30 19:44:31,283  INFO: 2021-06-01 10:54:00+08:00\tsend_order: self.cta_engine.send_order self.cta_engine :['BACKTESTING.1']\n",
      "2021-12-30 19:44:31,283  INFO: 2021-06-01 10:54:00+08:00\tsend_order: self.cta_engine.send_order self.cta_engine :['BACKTESTING.1']\n",
      "2021-12-30 19:44:31,283  INFO: 2021-06-01 10:54:00+08:00\tsend_order: self.cta_engine.send_order self.cta_engine :['BACKTESTING.1']\n",
      "2021-12-30 19:44:31,283  INFO: 2021-06-01 10:54:00+08:00\tsend_order: self.cta_engine.send_order self.cta_engine :['BACKTESTING.1']\n",
      "2021-12-30 19:44:31,283  INFO: 2021-06-01 10:54:00+08:00\tsend_order: self.cta_engine.send_order self.cta_engine :['BACKTESTING.1']\n",
      "2021-12-30 19:44:31,283  INFO: 2021-06-01 10:54:00+08:00\tsend_order: self.cta_engine.send_order self.cta_engine :['BACKTESTING.1']\n",
      "2021-12-30 19:44:31,283  INFO: 2021-06-01 10:54:00+08:00\tsend_order: self.cta_engine.send_order self.cta_engine :['BACKTESTING.1']\n",
      "2021-12-30 19:44:31,283  INFO: 2021-06-01 10:54:00+08:00\tsend_order: self.cta_engine.send_order self.cta_engine :['BACKTESTING.1']\n",
      "2021-12-30 19:44:31,283  INFO: 2021-06-01 10:54:00+08:00\tsend_order: self.cta_engine.send_order self.cta_engine :['BACKTESTING.1']\n",
      "2021-12-30 19:44:31,313  INFO: 2021-06-01 10:55:00+08:00\ttrade.datetime.date()2021-06-01\n",
      "2021-12-30 19:44:31,313  INFO: 2021-06-01 10:55:00+08:00\ttrade.datetime.date()2021-06-01\n",
      "2021-12-30 19:44:31,313  INFO: 2021-06-01 10:55:00+08:00\ttrade.datetime.date()2021-06-01\n",
      "2021-12-30 19:44:31,313  INFO: 2021-06-01 10:55:00+08:00\ttrade.datetime.date()2021-06-01\n",
      "2021-12-30 19:44:31,313  INFO: 2021-06-01 10:55:00+08:00\ttrade.datetime.date()2021-06-01\n",
      "2021-12-30 19:44:31,313  INFO: 2021-06-01 10:55:00+08:00\ttrade.datetime.date()2021-06-01\n",
      "2021-12-30 19:44:31,313  INFO: 2021-06-01 10:55:00+08:00\ttrade.datetime.date()2021-06-01\n",
      "2021-12-30 19:44:31,313  INFO: 2021-06-01 10:55:00+08:00\ttrade.datetime.date()2021-06-01\n",
      "2021-12-30 19:44:31,313  INFO: 2021-06-01 10:55:00+08:00\ttrade.datetime.date()2021-06-01\n",
      "2021-12-30 19:44:31,322  INFO: 2021-06-01 10:55:00+08:00\tcalculate_result:TradeData(gateway_name='BACKTESTING', symbol='I2109', exchange=<Exchange.DCE: 'DCE'>, orderid='1', tradeid='1', direction=<Direction.LONG: '多'>, offset=<Offset.OPEN: '开'>, price=1156.4, volume=1, datetime=datetime.datetime(2021, 6, 1, 10, 54, tzinfo=<DstTzInfo 'Asia/Shanghai' CST+8:00:00 STD>), investor=None) \n",
      "2021-12-30 19:44:31,322  INFO: 2021-06-01 10:55:00+08:00\tcalculate_result:TradeData(gateway_name='BACKTESTING', symbol='I2109', exchange=<Exchange.DCE: 'DCE'>, orderid='1', tradeid='1', direction=<Direction.LONG: '多'>, offset=<Offset.OPEN: '开'>, price=1156.4, volume=1, datetime=datetime.datetime(2021, 6, 1, 10, 54, tzinfo=<DstTzInfo 'Asia/Shanghai' CST+8:00:00 STD>), investor=None) \n",
      "2021-12-30 19:44:31,322  INFO: 2021-06-01 10:55:00+08:00\tcalculate_result:TradeData(gateway_name='BACKTESTING', symbol='I2109', exchange=<Exchange.DCE: 'DCE'>, orderid='1', tradeid='1', direction=<Direction.LONG: '多'>, offset=<Offset.OPEN: '开'>, price=1156.4, volume=1, datetime=datetime.datetime(2021, 6, 1, 10, 54, tzinfo=<DstTzInfo 'Asia/Shanghai' CST+8:00:00 STD>), investor=None) \n",
      "2021-12-30 19:44:31,322  INFO: 2021-06-01 10:55:00+08:00\tcalculate_result:TradeData(gateway_name='BACKTESTING', symbol='I2109', exchange=<Exchange.DCE: 'DCE'>, orderid='1', tradeid='1', direction=<Direction.LONG: '多'>, offset=<Offset.OPEN: '开'>, price=1156.4, volume=1, datetime=datetime.datetime(2021, 6, 1, 10, 54, tzinfo=<DstTzInfo 'Asia/Shanghai' CST+8:00:00 STD>), investor=None) \n",
      "2021-12-30 19:44:31,322  INFO: 2021-06-01 10:55:00+08:00\tcalculate_result:TradeData(gateway_name='BACKTESTING', symbol='I2109', exchange=<Exchange.DCE: 'DCE'>, orderid='1', tradeid='1', direction=<Direction.LONG: '多'>, offset=<Offset.OPEN: '开'>, price=1156.4, volume=1, datetime=datetime.datetime(2021, 6, 1, 10, 54, tzinfo=<DstTzInfo 'Asia/Shanghai' CST+8:00:00 STD>), investor=None) \n",
      "2021-12-30 19:44:31,322  INFO: 2021-06-01 10:55:00+08:00\tcalculate_result:TradeData(gateway_name='BACKTESTING', symbol='I2109', exchange=<Exchange.DCE: 'DCE'>, orderid='1', tradeid='1', direction=<Direction.LONG: '多'>, offset=<Offset.OPEN: '开'>, price=1156.4, volume=1, datetime=datetime.datetime(2021, 6, 1, 10, 54, tzinfo=<DstTzInfo 'Asia/Shanghai' CST+8:00:00 STD>), investor=None) \n",
      "2021-12-30 19:44:31,322  INFO: 2021-06-01 10:55:00+08:00\tcalculate_result:TradeData(gateway_name='BACKTESTING', symbol='I2109', exchange=<Exchange.DCE: 'DCE'>, orderid='1', tradeid='1', direction=<Direction.LONG: '多'>, offset=<Offset.OPEN: '开'>, price=1156.4, volume=1, datetime=datetime.datetime(2021, 6, 1, 10, 54, tzinfo=<DstTzInfo 'Asia/Shanghai' CST+8:00:00 STD>), investor=None) \n",
      "2021-12-30 19:44:31,322  INFO: 2021-06-01 10:55:00+08:00\tcalculate_result:TradeData(gateway_name='BACKTESTING', symbol='I2109', exchange=<Exchange.DCE: 'DCE'>, orderid='1', tradeid='1', direction=<Direction.LONG: '多'>, offset=<Offset.OPEN: '开'>, price=1156.4, volume=1, datetime=datetime.datetime(2021, 6, 1, 10, 54, tzinfo=<DstTzInfo 'Asia/Shanghai' CST+8:00:00 STD>), investor=None) \n",
      "2021-12-30 19:44:31,322  INFO: 2021-06-01 10:55:00+08:00\tcalculate_result:TradeData(gateway_name='BACKTESTING', symbol='I2109', exchange=<Exchange.DCE: 'DCE'>, orderid='1', tradeid='1', direction=<Direction.LONG: '多'>, offset=<Offset.OPEN: '开'>, price=1156.4, volume=1, datetime=datetime.datetime(2021, 6, 1, 10, 54, tzinfo=<DstTzInfo 'Asia/Shanghai' CST+8:00:00 STD>), investor=None) \n",
      "  File \"c:\\vnstudio\\lib\\runpy.py\", line 193, in _run_module_as_main\n",
      "    \"__main__\", mod_spec)\n",
      "  File \"c:\\vnstudio\\lib\\runpy.py\", line 85, in _run_code\n",
      "    exec(code, run_globals)\n",
      "  File \"c:\\vnstudio\\lib\\site-packages\\ipykernel_launcher.py\", line 16, in <module>\n",
      "    app.launch_new_instance()\n",
      "  File \"c:\\vnstudio\\lib\\site-packages\\traitlets\\config\\application.py\", line 845, in launch_instance\n",
      "    app.start()\n",
      "  File \"c:\\vnstudio\\lib\\site-packages\\ipykernel\\kernelapp.py\", line 667, in start\n",
      "    self.io_loop.start()\n",
      "  File \"c:\\vnstudio\\lib\\site-packages\\tornado\\platform\\asyncio.py\", line 199, in start\n",
      "    self.asyncio_loop.run_forever()\n",
      "  File \"c:\\vnstudio\\lib\\asyncio\\base_events.py\", line 528, in run_forever\n",
      "    self._run_once()\n",
      "  File \"c:\\vnstudio\\lib\\asyncio\\base_events.py\", line 1764, in _run_once\n",
      "    handle._run()\n",
      "  File \"c:\\vnstudio\\lib\\asyncio\\events.py\", line 88, in _run\n",
      "    self._context.run(self._callback, *self._args)\n",
      "  File \"c:\\vnstudio\\lib\\site-packages\\ipykernel\\kernelbase.py\", line 456, in dispatch_queue\n",
      "    await self.process_one()\n",
      "  File \"c:\\vnstudio\\lib\\site-packages\\ipykernel\\kernelbase.py\", line 445, in process_one\n",
      "    await dispatch(*args)\n",
      "  File \"c:\\vnstudio\\lib\\site-packages\\ipykernel\\kernelbase.py\", line 352, in dispatch_shell\n",
      "    await result\n",
      "  File \"c:\\vnstudio\\lib\\site-packages\\ipykernel\\kernelbase.py\", line 647, in execute_request\n",
      "    reply_content = await reply_content\n",
      "  File \"c:\\vnstudio\\lib\\site-packages\\ipykernel\\ipkernel.py\", line 345, in do_execute\n",
      "    res = shell.run_cell(code, store_history=store_history, silent=silent)\n",
      "  File \"c:\\vnstudio\\lib\\site-packages\\ipykernel\\zmqshell.py\", line 532, in run_cell\n",
      "    return super(ZMQInteractiveShell, self).run_cell(*args, **kwargs)\n",
      "  File \"c:\\vnstudio\\lib\\site-packages\\IPython\\core\\interactiveshell.py\", line 2899, in run_cell\n",
      "    raw_cell, store_history, silent, shell_futures)\n",
      "  File \"c:\\vnstudio\\lib\\site-packages\\IPython\\core\\interactiveshell.py\", line 2944, in _run_cell\n",
      "    return runner(coro)\n",
      "  File \"c:\\vnstudio\\lib\\site-packages\\IPython\\core\\async_helpers.py\", line 68, in _pseudo_sync_runner\n",
      "    coro.send(None)\n",
      "  File \"c:\\vnstudio\\lib\\site-packages\\IPython\\core\\interactiveshell.py\", line 3170, in run_cell_async\n",
      "    interactivity=interactivity, compiler=compiler, result=result)\n",
      "  File \"c:\\vnstudio\\lib\\site-packages\\IPython\\core\\interactiveshell.py\", line 3361, in run_ast_nodes\n",
      "    if (await self.run_code(code, result,  async_=asy)):\n",
      "  File \"c:\\vnstudio\\lib\\site-packages\\IPython\\core\\interactiveshell.py\", line 3441, in run_code\n",
      "    exec(code_obj, self.user_global_ns, self.user_ns)\n",
      "  File \"C:\\Users\\zhang\\AppData\\Local\\Temp/ipykernel_8984/66826247.py\", line 1, in <module>\n",
      "    cProfile.run(\"runBacktesting()\", sort=\"cumulative\")\n",
      "  File \"c:\\vnstudio\\lib\\cProfile.py\", line 16, in run\n",
      "    return _pyprofile._Utils(Profile).run(statement, filename, sort)\n",
      "  File \"c:\\vnstudio\\lib\\profile.py\", line 53, in run\n",
      "    prof.run(statement)\n",
      "  File \"c:\\vnstudio\\lib\\cProfile.py\", line 95, in run\n",
      "    return self.runctx(cmd, dict, dict)\n",
      "  File \"c:\\vnstudio\\lib\\cProfile.py\", line 100, in runctx\n",
      "    exec(cmd, globals, locals)\n",
      "  File \"<string>\", line 1, in <module>\n",
      "  File \"C:\\Users\\zhang\\AppData\\Local\\Temp/ipykernel_8984/3726379257.py\", line 17, in runBacktesting\n",
      "    engine.calculate_result()\n",
      "  File \"c:\\vnstudio\\lib\\site-packages\\vnpy\\app\\cta_strategy\\backtesting.py\", line 412, in calculate_result\n",
      "2021-12-30 19:44:31,329  INFO: 2021-06-01 10:55:00+08:00\tNone\n"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "2021-12-30 19:44:31,329  INFO: 2021-06-01 10:55:00+08:00\tNone\n",
      "2021-12-30 19:44:31,329  INFO: 2021-06-01 10:55:00+08:00\tNone\n",
      "2021-12-30 19:44:31,329  INFO: 2021-06-01 10:55:00+08:00\tNone\n",
      "2021-12-30 19:44:31,329  INFO: 2021-06-01 10:55:00+08:00\tNone\n",
      "2021-12-30 19:44:31,329  INFO: 2021-06-01 10:55:00+08:00\tNone\n",
      "2021-12-30 19:44:31,329  INFO: 2021-06-01 10:55:00+08:00\tNone\n",
      "2021-12-30 19:44:31,329  INFO: 2021-06-01 10:55:00+08:00\tNone\n",
      "2021-12-30 19:44:31,329  INFO: 2021-06-01 10:55:00+08:00\tNone\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "2021-12-30 19:44:31.272492\t加载进度：########## [93%]\n",
      "2021-12-30 19:44:31.273917\t历史数据加载完成，数据量：25635\n",
      "2021-12-30 19:44:31.288590\t触发异常，回测终止\n",
      "2021-12-30 19:44:31.313828\tTraceback (most recent call last):\n",
      "  File \"c:\\vnstudio\\lib\\site-packages\\vnpy\\app\\cta_strategy\\backtesting.py\", line 352, in run_backtesting\n",
      "    def run_backtesting(self):\n",
      "  File \"c:\\vnstudio\\lib\\site-packages\\vnpy\\app\\cta_strategy\\strategies\\atr_rsi_strategy.py\", line 118, in on_bar\n",
      "    self.sell(long_stop, abs(self.pos), stop=True)\n",
      "  File \"c:\\vnstudio\\lib\\site-packages\\vnpy\\app\\cta_strategy\\template.py\", line 234, in sell\n",
      "    net\n",
      "  File \"c:\\vnstudio\\lib\\site-packages\\vnpy\\app\\cta_strategy\\template.py\", line 349, in send_order\n",
      "    self, direction, offset, price, volume, stop, lock, net\n",
      "  File \"c:\\vnstudio\\lib\\site-packages\\vnpy\\app\\cta_strategy\\backtesting.py\", line 1165, in send_order\n",
      "KeyError: 'STOP.1'\n",
      "\n",
      "2021-12-30 19:44:31.313828\t开始计算逐日盯市盈亏1\n",
      "         3988594 function calls (3987285 primitive calls) in 2.557 seconds\n",
      "\n",
      "   Ordered by: cumulative time\n",
      "\n",
      "   ncalls  tottime  percall  cumtime  percall filename:lineno(function)\n",
      "        1    0.000    0.000    2.557    2.557 {built-in method builtins.exec}\n",
      "        1    0.000    0.000    2.557    2.557 <string>:1(<module>)\n",
      "        1    0.000    0.000    2.557    2.557 3726379257.py:1(runBacktesting)\n",
      "        1    0.000    0.000    2.479    2.479 backtesting.py:274(load_data)\n",
      "       11    0.000    0.000    2.476    0.225 backtesting.py:1500(load_bar_data)\n",
      "       11    0.075    0.007    2.475    0.225 sqlite_database.py:230(load_bar_data)\n",
      "    25646    0.022    0.000    1.778    0.000 peewee.py:4374(next)\n",
      "    25646    0.028    0.000    1.755    0.000 peewee.py:4287(iterate)\n",
      "    25635    0.063    0.000    1.434    0.000 peewee.py:7483(process_row)\n",
      "    25635    0.094    0.000    1.134    0.000 peewee.py:7441(process_row)\n",
      "   281985    0.062    0.000    1.040    0.000 peewee.py:4540(python_value)\n",
      "    25657    0.014    0.000    0.928    0.000 peewee.py:4952(adapt)\n",
      "    25635    0.377    0.000    0.913    0.000 peewee.py:4919(format_date_time)\n",
      "    51270    0.023    0.000    0.534    0.000 {built-in method strptime}\n",
      "    51270    0.034    0.000    0.511    0.000 _strptime.py:574(_strptime_datetime)\n",
      "    25635    0.121    0.000    0.502    0.000 tzinfo.py:258(localize)\n",
      "    51270    0.244    0.000    0.477    0.000 _strptime.py:318(_strptime)\n",
      "    25646    0.277    0.000    0.277    0.000 {method 'fetchone' of 'sqlite3.Cursor' objects}\n",
      "    25635    0.061    0.000    0.234    0.000 peewee.py:6251(__init__)\n",
      "    51270    0.031    0.000    0.221    0.000 tzinfo.py:203(normalize)\n",
      "   256350    0.215    0.000    0.215    0.000 {method 'replace' of 'datetime.datetime' objects}\n",
      "   281985    0.057    0.000    0.169    0.000 {built-in method builtins.setattr}\n",
      "    51270    0.047    0.000    0.149    0.000 tzinfo.py:193(fromutc)\n",
      "    51270    0.019    0.000    0.148    0.000 _strptime.py:26(_getlang)\n",
      "   358890    0.117    0.000    0.139    0.000 peewee.py:4400(__set__)\n",
      "    51270    0.023    0.000    0.129    0.000 locale.py:571(getlocale)\n",
      "   410195    0.057    0.000    0.066    0.000 {method 'add' of 'set' objects}\n",
      "    51270    0.016    0.000    0.058    0.000 locale.py:467(_parse_localename)\n",
      "    51270    0.048    0.000    0.048    0.000 {built-in method _locale.setlocale}\n",
      "    51270    0.029    0.000    0.042    0.000 locale.py:384(normalize)\n",
      "        1    0.000    0.000    0.040    0.040 backtesting.py:330(run_backtesting)\n",
      "    51272    0.017    0.000    0.040    0.000 enum.py:283(__call__)\n",
      "    51272    0.035    0.000    0.035    0.000 {method 'match' of 're.Pattern' objects}\n",
      "        5    0.000    0.000    0.029    0.006 backtesting.py:1266(write_log)\n",
      "        5    0.000    0.000    0.029    0.006 __init__.py:1434(log)\n",
      "        5    0.000    0.000    0.029    0.006 __init__.py:1496(_log)\n",
      "        5    0.000    0.000    0.028    0.006 __init__.py:1521(handle)\n",
      "        5    0.000    0.000    0.028    0.006 __init__.py:1575(callHandlers)\n",
      "       90    0.000    0.000    0.028    0.000 __init__.py:892(handle)\n",
      "       90    0.000    0.000    0.028    0.000 __init__.py:1022(emit)\n",
      "        1    0.000    0.000    0.027    0.027 backtesting.py:391(calculate_result)\n",
      "    78389    0.019    0.000    0.026    0.000 peewee.py:4395(__get__)\n",
      "        2    0.000    0.000    0.026    0.013 traceback.py:318(extract)\n",
      "        1    0.000    0.000    0.026    0.026 traceback.py:165(format_exc)\n",
      "        1    0.000    0.000    0.025    0.025 traceback.py:108(format_exception)\n",
      "        1    0.000    0.000    0.025    0.025 traceback.py:465(__init__)\n",
      "      104    0.000    0.000    0.024    0.000 traceback.py:282(line)\n",
      "       34    0.000    0.000    0.024    0.001 linecache.py:15(getline)\n",
      "       34    0.000    0.000    0.023    0.001 linecache.py:37(getlines)\n",
      "        2    0.000    0.000    0.023    0.012 linecache.py:82(updatecache)\n",
      "    76938    0.017    0.000    0.023    0.000 peewee.py:4685(adapt)\n",
      "    51272    0.023    0.000    0.023    0.000 enum.py:525(__new__)\n",
      "   102540    0.022    0.000    0.022    0.000 {built-in method _bisect.bisect_right}\n",
      "        1    0.001    0.001    0.022    0.022 tokenize.py:443(open)\n",
      "        2    0.022    0.011    0.022    0.011 {built-in method io.open}\n",
      "   207763    0.022    0.000    0.022    0.000 {method 'get' of 'dict' objects}\n",
      "   153810    0.021    0.000    0.021    0.000 peewee.py:4642(adapt)\n",
      "    53198    0.021    0.000    0.021    0.000 {method 'append' of 'list' objects}\n",
      "       90    0.000    0.000    0.020    0.000 __init__.py:1011(flush)\n",
      "       11    0.000    0.000    0.019    0.002 peewee.py:6872(__iter__)\n",
      "       11    0.000    0.000    0.019    0.002 peewee.py:1901(inner)\n",
      "       11    0.000    0.000    0.019    0.002 peewee.py:1976(execute)\n",
      "       11    0.001    0.000    0.019    0.002 peewee.py:2148(_execute)\n",
      "       11    0.000    0.000    0.018    0.002 peewee.py:3154(execute)\n",
      "    25635    0.017    0.000    0.017    0.000 {method 'groupdict' of 're.Match' objects}\n",
      "   102749    0.017    0.000    0.017    0.000 {built-in method builtins.max}\n",
      "   208017    0.016    0.000    0.016    0.000 {built-in method builtins.isinstance}\n",
      "       45    0.000    0.000    0.015    0.000 iostream.py:441(flush)\n",
      "       45    0.000    0.000    0.013    0.000 threading.py:534(wait)\n",
      "       45    0.000    0.000    0.013    0.000 threading.py:264(wait)\n",
      "      547    0.013    0.000    0.013    0.000 {method 'acquire' of '_thread.lock' objects}\n",
      "  1221/11    0.002    0.000    0.011    0.001 peewee.py:611(sql)\n",
      "       11    0.000    0.000    0.011    0.001 peewee.py:2379(__sql__)\n",
      "      101    0.000    0.000    0.010    0.000 atr_rsi_strategy.py:86(on_bar)\n",
      "103347/103338    0.010    0.000    0.010    0.000 {built-in method builtins.len}\n",
      "        1    0.003    0.003    0.009    0.009 backtesting.py:120(__init__)\n",
      "        2    0.000    0.000    0.009    0.004 template.py:394(write_log)\n",
      "    51274    0.009    0.000    0.009    0.000 tzinfo.py:396(utcoffset)\n",
      "      180    0.001    0.000    0.008    0.000 iostream.py:490(write)\n",
      "      322    0.001    0.000    0.007    0.000 iostream.py:206(schedule)\n",
      "       45    0.000    0.000    0.007    0.000 __init__.py:1123(emit)\n",
      "      322    0.006    0.000    0.006    0.000 socket.py:474(send)\n",
      "       11    0.000    0.000    0.006    0.001 peewee.py:3131(execute_sql)\n",
      "      187    0.000    0.000    0.006    0.000 peewee.py:4549(__sql__)\n",
      "    25635    0.006    0.000    0.006    0.000 peewee.py:4592(adapt)\n",
      "       11    0.005    0.000    0.005    0.000 {method 'execute' of 'sqlite3.Cursor' objects}\n",
      "      187    0.000    0.000    0.005    0.000 peewee.py:1258(__sql__)\n",
      "    51287    0.005    0.000    0.005    0.000 {method 'lower' of 'str' objects}\n",
      "       45    0.005    0.000    0.005    0.000 {method 'flush' of '_io.TextIOWrapper' objects}\n",
      "       33    0.000    0.000    0.005    0.000 peewee.py:1765(__sql__)\n",
      "      101    0.002    0.000    0.005    0.000 utility.py:596(update_bar)\n",
      "    99/11    0.001    0.000    0.005    0.000 peewee.py:1448(__sql__)\n",
      "    51270    0.004    0.000    0.004    0.000 {method 'toordinal' of 'datetime.date' objects}\n",
      "        2    0.000    0.000    0.004    0.002 template.py:333(send_order)\n",
      "       11    0.000    0.000    0.004    0.000 peewee.py:7224(__sql_selection__)\n",
      "        1    0.000    0.000    0.004    0.004 atr_rsi_strategy.py:57(on_init)\n",
      "        1    0.000    0.000    0.004    0.004 template.py:191(buy)\n",
      "    25635    0.004    0.000    0.004    0.000 {method 'clear' of 'set' objects}\n",
      "    25636    0.004    0.000    0.004    0.000 {method 'pop' of 'dict' objects}\n",
      "        1    0.000    0.000    0.003    0.003 backtesting.py:192(add_file_handler)\n",
      "       10    0.003    0.000    0.003    0.000 peewee.py:7374(_initialize_columns)\n",
      "        1    0.000    0.000    0.003    0.003 frame.py:1124(from_dict)\n",
      "        1    0.000    0.000    0.003    0.003 frame.py:397(__init__)\n",
      "        1    0.000    0.000    0.003    0.003 construction.py:216(init_dict)\n",
      "       22    0.003    0.000    0.003    0.000 {built-in method nt.stat}\n",
      "    25635    0.003    0.000    0.003    0.000 {method 'end' of 're.Match' objects}\n",
      "    25838    0.003    0.000    0.003    0.000 {method 'keys' of 'dict' objects}\n",
      "    25635    0.003    0.000    0.003    0.000 {method 'pop' of 'set' objects}\n",
      "       45    0.000    0.000    0.003    0.000 {built-in method builtins.print}\n",
      "    25635    0.002    0.000    0.002    0.000 peewee.py:4920(<lambda>)\n",
      "       21    0.000    0.000    0.002    0.000 compilerop.py:181(check_linecache_ipython)\n",
      "       21    0.000    0.000    0.002    0.000 linecache.py:53(checkcache)\n",
      "      4/2    0.000    0.000    0.002    0.001 base.py:277(__new__)\n",
      "        1    0.000    0.000    0.002    0.002 __init__.py:1354(setLevel)\n",
      "        1    0.002    0.002    0.002    0.002 __init__.py:1309(_clear_cache)\n",
      "      198    0.000    0.000    0.002    0.000 peewee.py:976(__sql__)\n",
      "       90    0.000    0.000    0.002    0.000 __init__.py:869(format)\n",
      "       16    0.000    0.000    0.002    0.000 backtesting.py:1310(output)\n",
      "        2    0.000    0.000    0.002    0.001 pathlib.py:883(joinpath)\n",
      "       90    0.000    0.000    0.002    0.000 __init__.py:606(format)\n",
      "      444    0.000    0.000    0.002    0.000 {built-in method builtins.next}\n",
      "    25635    0.002    0.000    0.002    0.000 {method 'weekday' of 'datetime.date' objects}\n",
      "        2    0.000    0.000    0.002    0.001 pathlib.py:678(_make_child)\n",
      "      352    0.000    0.000    0.002    0.000 peewee.py:581(__call__)\n",
      "        1    0.000    0.000    0.002    0.002 traceback.py:181(print_stack)\n",
      "        2    0.000    0.000    0.002    0.001 pathlib.py:624(_parse_args)\n",
      "      440    0.000    0.000    0.002    0.000 peewee.py:546(inner)\n",
      "      202    0.000    0.000    0.002    0.000 <__array_function__ internals>:2(mean)\n",
      "        2    0.000    0.000    0.002    0.001 pathlib.py:53(parse_parts)\n",
      "        2    0.002    0.001    0.002    0.001 {built-in method sys.intern}\n",
      "      187    0.000    0.000    0.002    0.000 peewee.py:803(apply_column)\n",
      "      220    0.000    0.000    0.002    0.000 contextlib.py:107(__enter__)\n",
      "      202    0.000    0.000    0.002    0.000 {built-in method numpy.core._multiarray_umath.implement_array_function}\n",
      "        1    0.000    0.000    0.001    0.001 frame.py:4287(set_index)\n",
      "      202    0.000    0.000    0.001    0.000 fromnumeric.py:3322(mean)\n",
      "       11    0.000    0.000    0.001    0.000 peewee.py:6273(select)\n",
      "      180    0.000    0.000    0.001    0.000 iostream.py:427(_schedule_flush)\n",
      "        4    0.000    0.000    0.001    0.000 common.py:1163(is_datetime64_any_dtype)\n",
      "        1    0.001    0.001    0.001    0.001 base.py:4228(__contains__)\n",
      "      204    0.000    0.000    0.001    0.000 _methods.py:162(_mean)\n",
      "       14    0.000    0.000    0.001    0.000 common.py:1886(_is_dtype_type)\n",
      "        4    0.000    0.000    0.001    0.000 common.py:508(is_datetime64_dtype)\n",
      "      352    0.001    0.000    0.001    0.000 peewee.py:527(__call__)\n",
      "       90    0.000    0.000    0.001    0.000 __init__.py:539(formatTime)\n",
      "       11    0.000    0.000    0.001    0.000 peewee.py:6933(__init__)\n",
      "        6    0.001    0.000    0.001    0.000 {pandas._libs.lib.is_list_like}\n",
      "      396    0.000    0.000    0.001    0.000 peewee.py:1502(__sql__)\n",
      "        1    0.001    0.001    0.001    0.001 {method 'readlines' of '_io._IOBase' objects}\n",
      "        1    0.000    0.000    0.001    0.001 utility.py:75(get_folder_path)\n",
      "        1    0.000    0.000    0.001    0.001 traceback.py:19(print_list)\n",
      "        1    0.000    0.000    0.001    0.001 construction.py:69(arrays_to_mgr)\n",
      "       11    0.000    0.000    0.001    0.000 peewee.py:3175(get_sql_context)\n",
      "      508    0.001    0.000    0.001    0.000 {method 'reduce' of 'numpy.ufunc' objects}\n",
      "        1    0.000    0.000    0.001    0.001 traceback.py:200(extract_stack)\n",
      "        1    0.000    0.000    0.001    0.001 backtesting.py:266(add_strategy)\n",
      "        1    0.000    0.000    0.001    0.001 atr_rsi_strategy.py:51(__init__)\n",
      "        1    0.001    0.001    0.001    0.001 backtesting.py:230(set_parameters)\n",
      "       11    0.001    0.000    0.001    0.000 peewee.py:556(__init__)\n",
      "        1    0.000    0.000    0.001    0.001 __init__.py:1074(__init__)\n",
      "        1    0.000    0.000    0.001    0.001 __init__.py:1116(_open)\n",
      "      367    0.000    0.000    0.001    0.000 threading.py:1080(is_alive)\n",
      "       11    0.001    0.000    0.001    0.000 {method 'extend' of 'list' objects}\n",
      "        1    0.000    0.000    0.001    0.001 pathlib.py:1324(exists)\n",
      "        1    0.000    0.000    0.001    0.001 pathlib.py:1146(stat)\n",
      "       55    0.000    0.000    0.001    0.000 peewee.py:1374(__sql__)\n",
      "      220    0.000    0.000    0.001    0.000 contextlib.py:116(__exit__)\n",
      "      202    0.000    0.000    0.001    0.000 {method 'max' of 'numpy.ndarray' objects}\n",
      "       90    0.001    0.000    0.001    0.000 {built-in method time.strftime}\n",
      "       11    0.000    0.000    0.001    0.000 peewee.py:6808(__init__)\n",
      "       55    0.000    0.000    0.000    0.000 peewee.py:623(value)\n",
      "        1    0.000    0.000    0.000    0.000 managers.py:1691(create_block_manager_from_arrays)\n",
      "      198    0.000    0.000    0.000    0.000 peewee.py:505(__getitem__)\n",
      "       11    0.000    0.000    0.000    0.000 peewee.py:2085(_apply_ordering)\n",
      "       90    0.000    0.000    0.000    0.000 {built-in method time.localtime}\n",
      "        5    0.000    0.000    0.000    0.000 __init__.py:1481(makeRecord)\n",
      "      202    0.000    0.000    0.000    0.000 _methods.py:38(_amax)\n",
      "        1    0.000    0.000    0.000    0.000 construction.py:331(extract_index)\n",
      "       11    0.000    0.000    0.000    0.000 peewee.py:6918(_normalize_model_select)\n",
      "      363    0.000    0.000    0.000    0.000 peewee.py:524(__new__)\n",
      "        5    0.000    0.000    0.000    0.000 __init__.py:293(__init__)\n",
      "       11    0.000    0.000    0.000    0.000 peewee.py:2273(__init__)\n",
      "      220    0.000    0.000    0.000    0.000 contextlib.py:237(helper)\n",
      "     1100    0.000    0.000    0.000    0.000 peewee.py:619(literal)\n",
      "      198    0.000    0.000    0.000    0.000 peewee.py:498(get)\n",
      "       45    0.000    0.000    0.000    0.000 threading.py:499(__init__)\n",
      "      352    0.000    0.000    0.000    0.000 peewee.py:600(__exit__)\n",
      "      396    0.000    0.000    0.000    0.000 peewee.py:1490(__init__)\n",
      "      204    0.000    0.000    0.000    0.000 _methods.py:66(_count_reduce_items)\n",
      "      187    0.000    0.000    0.000    0.000 peewee.py:4530(column)\n",
      "      253    0.000    0.000    0.000    0.000 peewee.py:383(<lambda>)\n",
      "      198    0.000    0.000    0.000    0.000 peewee.py:492(add)\n",
      "      396    0.000    0.000    0.000    0.000 peewee.py:378(quote)\n",
      "        1    0.000    0.000    0.000    0.000 managers.py:126(__init__)\n",
      "      803    0.000    0.000    0.000    0.000 peewee.py:541(__getattr__)\n",
      "      220    0.000    0.000    0.000    0.000 contextlib.py:81(__init__)\n",
      "        1    0.000    0.000    0.000    0.000 utility.py:571(__init__)\n",
      "       11    0.000    0.000    0.000    0.000 peewee.py:810(__init__)\n",
      "      367    0.000    0.000    0.000    0.000 threading.py:1038(_wait_for_tstate_lock)\n",
      "       16    0.000    0.000    0.000    0.000 base.py:231(is_dtype)\n",
      "        1    0.000    0.000    0.000    0.000 managers.py:216(_rebuild_blknos_and_blklocs)\n",
      "      352    0.000    0.000    0.000    0.000 peewee.py:595(__enter__)\n",
      "       11    0.000    0.000    0.000    0.000 peewee.py:6818(_get_cursor_wrapper)\n",
      "      101    0.000    0.000    0.000    0.000 {method 'min' of 'numpy.ndarray' objects}\n",
      "       90    0.000    0.000    0.000    0.000 __init__.py:590(formatMessage)\n",
      "       22    0.000    0.000    0.000    0.000 peewee.py:713(inner)\n",
      "        1    0.000    0.000    0.000    0.000 template.py:20(__init__)\n",
      "      979    0.000    0.000    0.000    0.000 peewee.py:569(scope)\n",
      "        1    0.000    0.000    0.000    0.000 __init__.py:1930(getLogger)\n",
      "      396    0.000    0.000    0.000    0.000 peewee.py:1491(<listcomp>)\n",
      "       90    0.000    0.000    0.000    0.000 __init__.py:584(usesTime)\n",
      "       45    0.000    0.000    0.000    0.000 threading.py:216(__init__)\n",
      "      363    0.000    0.000    0.000    0.000 <string>:1(__new__)\n",
      "       33    0.000    0.000    0.000    0.000 peewee.py:1167(__eq__)\n",
      "       11    0.000    0.000    0.000    0.000 peewee.py:766(__init__)\n",
      "      101    0.000    0.000    0.000    0.000 _methods.py:42(_amin)\n",
      "       45    0.000    0.000    0.000    0.000 threading.py:252(_acquire_restore)\n",
      "       11    0.000    0.000    0.000    0.000 peewee.py:7123(_get_model_cursor_wrapper)\n",
      "       90    0.000    0.000    0.000    0.000 __init__.py:432(format)\n",
      "      101    0.000    0.000    0.000    0.000 template.py:387(cancel_all)\n",
      "      180    0.000    0.000    0.000    0.000 iostream.py:408(_is_master_process)\n",
      "      253    0.000    0.000    0.000    0.000 inspect.py:72(isclass)\n",
      "       90    0.000    0.000    0.000    0.000 {built-in method _thread.allocate_lock}\n",
      "        1    0.000    0.000    0.000    0.000 backtesting.py:177(add_null_handler)\n",
      "        2    0.000    0.000    0.000    0.000 traceback.py:385(format)\n",
      "      444    0.000    0.000    0.000    0.000 {method 'join' of 'str' objects}\n",
      "      322    0.000    0.000    0.000    0.000 iostream.py:96(_event_pipe)\n",
      "       55    0.000    0.000    0.000    0.000 peewee.py:4537(db_value)\n",
      "        2    0.000    0.000    0.000    0.000 utility.py:850(atr)\n",
      "      180    0.000    0.000    0.000    0.000 __init__.py:849(acquire)\n",
      "        5    0.000    0.000    0.000    0.000 __init__.py:1451(findCaller)\n",
      "        4    0.000    0.000    0.000    0.000 common.py:240(asarray_tuplesafe)\n",
      "        2    0.000    0.000    0.000    0.000 backtesting.py:1144(send_order)\n",
      "        1    0.000    0.000    0.000    0.000 <string>:1(__repr__)\n",
      "       11    0.000    0.000    0.000    0.000 peewee.py:7478(__init__)\n",
      "       16    0.000    0.000    0.000    0.000 __init__.py:1619(isEnabledFor)\n",
      "       11    0.000    0.000    0.000    0.000 __init__.py:1361(debug)\n",
      "      101    0.000    0.000    0.000    0.000 backtesting.py:1254(cancel_all)\n",
      "       11    0.000    0.000    0.000    0.000 peewee.py:2036(__init__)\n",
      "       90    0.000    0.000    0.000    0.000 {method 'write' of '_io.TextIOWrapper' objects}\n",
      "        1    0.000    0.000    0.000    0.000 __init__.py:1221(getLogger)\n",
      "       90    0.000    0.000    0.000    0.000 __init__.py:429(usesTime)\n",
      "        1    0.000    0.000    0.000    0.000 base.py:710(_engine)\n",
      "      704    0.000    0.000    0.000    0.000 peewee.py:573(parentheses)\n",
      "        4    0.000    0.000    0.000    0.000 __init__.py:15(wrapper)\n",
      "       22    0.000    0.000    0.000    0.000 peewee.py:794(apply_alias)\n",
      "       22    0.000    0.000    0.000    0.000 peewee.py:6940(clone)\n",
      "      180    0.000    0.000    0.000    0.000 __init__.py:856(release)\n",
      "        5    0.000    0.000    0.000    0.000 ntpath.py:212(basename)\n",
      "        1    0.000    0.000    0.000    0.000 managers.py:1726(form_blocks)\n",
      "       11    0.000    0.000    0.000    0.000 peewee.py:3123(cursor)\n",
      "        2    0.000    0.000    0.000    0.000 {pandas._libs.lib.infer_dtype}\n",
      "        2    0.000    0.000    0.000    0.000 cast.py:1239(construct_1d_object_array_from_listlike)\n",
      "       11    0.000    0.000    0.000    0.000 peewee.py:3263(in_transaction)\n",
      "        5    0.000    0.000    0.000    0.000 ntpath.py:178(split)\n",
      "        3    0.000    0.000    0.000    0.000 __init__.py:813(__init__)\n",
      "       22    0.000    0.000    0.000    0.000 peewee.py:2297(clone)\n",
      "        1    0.000    0.000    0.000    0.000 tokenize.py:350(detect_encoding)\n",
      "        8    0.000    0.000    0.000    0.000 common.py:642(is_interval_dtype)\n",
      "       11    0.000    0.000    0.000    0.000 peewee.py:481(__init__)\n",
      "        2    0.000    0.000    0.000    0.000 __init__.py:276(__getattr__)\n",
      "      389    0.000    0.000    0.000    0.000 {built-in method __new__ of type object at 0x00007FFE47366D30}\n",
      "      200    0.000    0.000    0.000    0.000 {method 'find' of 'str' objects}\n",
      "        8    0.000    0.000    0.000    0.000 codecs.py:319(decode)\n",
      "      242    0.000    0.000    0.000    0.000 peewee.py:247(__getattr__)\n",
      "       70    0.000    0.000    0.000    0.000 {method 'format' of 'str' objects}\n",
      "        8    0.000    0.000    0.000    0.000 common.py:678(is_categorical_dtype)\n",
      "        4    0.000    0.000    0.000    0.000 dtypes.py:1092(is_dtype)\n",
      "      334    0.000    0.000    0.000    0.000 {built-in method builtins.hasattr}\n",
      "        6    0.000    0.000    0.000    0.000 {built-in method numpy.zeros}\n",
      "      408    0.000    0.000    0.000    0.000 {method 'replace' of 'str' objects}\n",
      "        1    0.000    0.000    0.000    0.000 template.py:215(sell)\n",
      "      190    0.000    0.000    0.000    0.000 {method 'acquire' of '_thread.RLock' objects}\n",
      "       95    0.000    0.000    0.000    0.000 __init__.py:747(filter)\n",
      "        1    0.000    0.000    0.000    0.000 backtesting.py:183(add_console_handler)\n",
      "        8    0.000    0.000    0.000    0.000 traceback.py:588(format)\n",
      "       55    0.000    0.000    0.000    0.000 peewee.py:1362(__init__)\n",
      "        3    0.000    0.000    0.000    0.000 __init__.py:1531(addHandler)\n",
      "        4    0.000    0.000    0.000    0.000 {built-in method numpy.empty}\n",
      "       11    0.000    0.000    0.000    0.000 peewee.py:3159(get_context_options)\n",
      "       33    0.000    0.000    0.000    0.000 peewee.py:1777(CommaNodeList)\n",
      "        2    0.000    0.000    0.000    0.000 {talib._ta_lib.ATR}\n",
      "      208    0.000    0.000    0.000    0.000 peewee.py:5915(table)\n",
      "        8    0.000    0.000    0.000    0.000 {built-in method _codecs.utf_8_decode}\n",
      "       22    0.000    0.000    0.000    0.000 dbapi2.py:60(adapt_datetime)\n",
      "       22    0.000    0.000    0.000    0.000 peewee.py:1926(clone)\n",
      "      465    0.000    0.000    0.000    0.000 {built-in method builtins.issubclass}\n",
      "      407    0.000    0.000    0.000    0.000 peewee.py:488(mapping)\n",
      "        2    0.000    0.000    0.000    0.000 {built-in method _warnings.warn}\n",
      "       90    0.000    0.000    0.000    0.000 __init__.py:371(getMessage)\n",
      "        1    0.000    0.000    0.000    0.000 tokenize.py:374(read_or_stop)\n",
      "        4    0.000    0.000    0.000    0.000 common.py:539(is_datetime64tz_dtype)\n",
      "        1    0.000    0.000    0.000    0.000 __init__.py:513(__init__)\n",
      "       11    0.000    0.000    0.000    0.000 peewee.py:2050(where)\n",
      "      407    0.000    0.000    0.000    0.000 peewee.py:825(__hash__)\n",
      "      318    0.000    0.000    0.000    0.000 {built-in method builtins.getattr}\n",
      "       11    0.000    0.000    0.000    0.000 abc.py:137(__instancecheck__)\n",
      "        1    0.000    0.000    0.000    0.000 {method 'readline' of '_io.BufferedReader' objects}\n",
      "        2    0.000    0.000    0.000    0.000 __init__.py:1000(__init__)\n",
      "      132    0.000    0.000    0.000    0.000 {method 'copy' of 'dict' objects}\n",
      "        1    0.000    0.000    0.000    0.000 backtesting.py:1168(send_stop_order)\n",
      "       17    0.000    0.000    0.000    0.000 {built-in method now}\n",
      "      187    0.000    0.000    0.000    0.000 peewee.py:1245(__init__)\n",
      "      352    0.000    0.000    0.000    0.000 {method 'pop' of 'list' objects}\n",
      "        5    0.000    0.000    0.000    0.000 ntpath.py:201(splitext)\n",
      "       22    0.000    0.000    0.000    0.000 peewee.py:703(clone)\n",
      "       11    0.000    0.000    0.000    0.000 peewee.py:1915(__init__)\n",
      "        5    0.000    0.000    0.000    0.000 ntpath.py:44(normcase)\n",
      "      185    0.000    0.000    0.000    0.000 {built-in method nt.getpid}\n",
      "      367    0.000    0.000    0.000    0.000 threading.py:507(is_set)\n",
      "       45    0.000    0.000    0.000    0.000 threading.py:243(__exit__)\n",
      "       11    0.000    0.000    0.000    0.000 peewee.py:819(_update_hash)\n",
      "      131    0.000    0.000    0.000    0.000 {method 'update' of 'dict' objects}\n",
      "       99    0.000    0.000    0.000    0.000 peewee.py:1442(__init__)\n",
      "        1    0.000    0.000    0.000    0.000 managers.py:340(_verify_integrity)\n",
      "        1    0.000    0.000    0.000    0.000 {method 'strftime' of 'datetime.date' objects}\n",
      "       10    0.000    0.000    0.000    0.000 __init__.py:212(_acquireLock)\n",
      "        1    0.000    0.000    0.000    0.000 <string>:1(__init__)\n",
      "       11    0.000    0.000    0.000    0.000 peewee.py:577(subquery)\n",
      "        2    0.000    0.000    0.000    0.000 base.py:569(_simple_new)\n",
      "      123    0.000    0.000    0.000    0.000 {built-in method builtins.min}\n",
      "       22    0.000    0.000    0.000    0.000 {method 'isoformat' of 'datetime.datetime' objects}\n",
      "       66    0.000    0.000    0.000    0.000 peewee.py:1146(inner)\n",
      "        4    0.000    0.000    0.000    0.000 common.py:608(is_period_dtype)\n",
      "        1    0.000    0.000    0.000    0.000 {method 'any' of 'numpy.ndarray' objects}\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "       11    0.000    0.000    0.000    0.000 common.py:1743(is_extension_array_dtype)\n",
      "        3    0.000    0.000    0.000    0.000 __init__.py:794(_addHandlerRef)\n",
      "      367    0.000    0.000    0.000    0.000 {method 'append' of 'collections.deque' objects}\n",
      "        1    0.000    0.000    0.000    0.000 copy.py:66(copy)\n",
      "       68    0.000    0.000    0.000    0.000 generic.py:7(_check)\n",
      "        2    0.000    0.000    0.000    0.000 pathlib.py:694(__fspath__)\n",
      "        1    0.000    0.000    0.000    0.000 base.py:1012(_ndarray_values)\n",
      "        2    0.000    0.000    0.000    0.000 utility.py:123(round_to)\n",
      "        1    0.000    0.000    0.000    0.000 utility.py:312(__init__)\n",
      "      190    0.000    0.000    0.000    0.000 {method 'release' of '_thread.RLock' objects}\n",
      "        4    0.000    0.000    0.000    0.000 dtypes.py:912(is_dtype)\n",
      "       11    0.000    0.000    0.000    0.000 peewee.py:7369(__init__)\n",
      "       11    0.000    0.000    0.000    0.000 {method 'cursor' of 'sqlite3.Connection' objects}\n",
      "       11    0.000    0.000    0.000    0.000 {built-in method _abc._abc_instancecheck}\n",
      "       35    0.000    0.000    0.000    0.000 types.py:164(__get__)\n",
      "       23    0.000    0.000    0.000    0.000 enum.py:589(__hash__)\n",
      "       23    0.000    0.000    0.000    0.000 {built-in method nt.fspath}\n",
      "        2    0.000    0.000    0.000    0.000 pathlib.py:684(__str__)\n",
      "        1    0.000    0.000    0.000    0.000 _methods.py:54(_any)\n",
      "      204    0.000    0.000    0.000    0.000 {built-in method numpy.core._multiarray_umath.normalize_axis_index}\n",
      "        2    0.000    0.000    0.000    0.000 pathlib.py:657(_from_parsed_parts)\n",
      "        2    0.000    0.000    0.000    0.000 base.py:180(construct_from_string)\n",
      "        2    0.000    0.000    0.000    0.000 _dtype.py:321(_name_get)\n",
      "        1    0.000    0.000    0.000    0.000 template.py:47(update_setting)\n",
      "        5    0.000    0.000    0.000    0.000 genericpath.py:117(_splitext)\n",
      "        2    0.000    0.000    0.000    0.000 {pandas._libs.lib.is_scalar}\n",
      "       11    0.000    0.000    0.000    0.000 {built-in method builtins.iter}\n",
      "      175    0.000    0.000    0.000    0.000 {method 'strip' of 'str' objects}\n",
      "        5    0.000    0.000    0.000    0.000 ntpath.py:122(splitdrive)\n",
      "       11    0.000    0.000    0.000    0.000 peewee.py:511(push)\n",
      "      204    0.000    0.000    0.000    0.000 {built-in method numpy.asanyarray}\n",
      "       45    0.000    0.000    0.000    0.000 threading.py:240(__enter__)\n",
      "        2    0.000    0.000    0.000    0.000 pathlib.py:667(_format_parsed_parts)\n",
      "       11    0.000    0.000    0.000    0.000 peewee.py:653(query)\n",
      "       33    0.000    0.000    0.000    0.000 peewee.py:1754(__init__)\n",
      "      259    0.000    0.000    0.000    0.000 {built-in method builtins.abs}\n",
      "        5    0.000    0.000    0.000    0.000 __init__.py:154(<lambda>)\n",
      "        1    0.000    0.000    0.000    0.000 generic.py:162(__init__)\n",
      "       45    0.000    0.000    0.000    0.000 threading.py:255(_is_owned)\n",
      "        4    0.000    0.000    0.000    0.000 common.py:577(is_timedelta64_dtype)\n",
      "        3    0.000    0.000    0.000    0.000 enum.py:558(__repr__)\n",
      "        2    0.000    0.000    0.000    0.000 {method 'mean' of 'numpy.ndarray' objects}\n",
      "       11    0.000    0.000    0.000    0.000 peewee.py:4260(__iter__)\n",
      "        1    0.000    0.000    0.000    0.000 {built-in method numpy.arange}\n",
      "       45    0.000    0.000    0.000    0.000 threading.py:249(_release_save)\n",
      "        1    0.000    0.000    0.000    0.000 {method 'copy' of 'list' objects}\n",
      "        2    0.000    0.000    0.000    0.000 traceback.py:543(format_exception_only)\n",
      "       11    0.000    0.000    0.000    0.000 peewee.py:2145(_get_hash)\n",
      "       47    0.000    0.000    0.000    0.000 {method 'clear' of 'dict' objects}\n",
      "      202    0.000    0.000    0.000    0.000 fromnumeric.py:3317(_mean_dispatcher)\n",
      "        1    0.000    0.000    0.000    0.000 backtesting.py:1193(send_limit_order)\n",
      "        1    0.000    0.000    0.000    0.000 tzinfo.py:504(__repr__)\n",
      "        4    0.000    0.000    0.000    0.000 <frozen importlib._bootstrap>:416(parent)\n",
      "        3    0.000    0.000    0.000    0.000 managers.py:167(shape)\n",
      "        2    0.000    0.000    0.000    0.000 __init__.py:842(createLock)\n",
      "        2    0.000    0.000    0.000    0.000 dtypes.py:1040(construct_from_string)\n",
      "       10    0.000    0.000    0.000    0.000 __init__.py:221(_releaseLock)\n",
      "        1    0.000    0.000    0.000    0.000 backtesting.py:912(commit_virtual_trade)\n",
      "        2    0.000    0.000    0.000    0.000 common.py:1619(is_bool_dtype)\n",
      "        1    0.000    0.000    0.000    0.000 managers.py:654(_consolidate_check)\n",
      "       30    0.000    0.000    0.000    0.000 traceback.py:289(walk_stack)\n",
      "       34    0.000    0.000    0.000    0.000 linecache.py:147(lazycache)\n",
      "       11    0.000    0.000    0.000    0.000 peewee.py:4252(__init__)\n",
      "        2    0.000    0.000    0.000    0.000 utility.py:868(rsi)\n",
      "        1    0.000    0.000    0.000    0.000 base.py:3901(values)\n",
      "        2    0.000    0.000    0.000    0.000 pathlib.py:91(join_parsed_parts)\n",
      "        1    0.000    0.000    0.000    0.000 traceback.py:366(from_list)\n",
      "       18    0.000    0.000    0.000    0.000 {method 'startswith' of 'str' objects}\n",
      "        5    0.000    0.000    0.000    0.000 threading.py:1206(current_thread)\n",
      "        2    0.000    0.000    0.000    0.000 {method 'fill' of 'numpy.ndarray' objects}\n",
      "        6    0.000    0.000    0.000    0.000 <frozen importlib._bootstrap>:1009(_handle_fromlist)\n",
      "        2    0.000    0.000    0.000    0.000 _dtype.py:24(_kind_name)\n",
      "        5    0.000    0.000    0.000    0.000 __init__.py:117(getLevelName)\n",
      "       11    0.000    0.000    0.000    0.000 dtypes.py:83(find)\n",
      "       11    0.000    0.000    0.000    0.000 peewee.py:4367(__init__)\n",
      "        2    0.000    0.000    0.000    0.000 __init__.py:1605(getEffectiveLevel)\n",
      "        1    0.000    0.000    0.000    0.000 tokenize.py:380(find_cookie)\n",
      "        2    0.000    0.000    0.000    0.000 common.py:1006(is_signed_integer_dtype)\n",
      "        2    0.000    0.000    0.000    0.000 dtypes.py:717(construct_from_string)\n",
      "        5    0.000    0.000    0.000    0.000 process.py:180(name)\n",
      "       45    0.000    0.000    0.000    0.000 {built-in method _imp.lock_held}\n",
      "       35    0.000    0.000    0.000    0.000 enum.py:607(value)\n",
      "       45    0.000    0.000    0.000    0.000 {method '__exit__' of '_thread.lock' objects}\n",
      "       35    0.000    0.000    0.000    0.000 {built-in method builtins.hash}\n",
      "        2    0.000    0.000    0.000    0.000 traceback.py:153(_some_str)\n",
      "       11    0.000    0.000    0.000    0.000 peewee.py:508(__setitem__)\n",
      "        5    0.000    0.000    0.000    0.000 ntpath.py:34(_get_bothseps)\n",
      "        2    0.000    0.000    0.000    0.000 threading.py:75(RLock)\n",
      "       34    0.000    0.000    0.000    0.000 traceback.py:243(__init__)\n",
      "       15    0.000    0.000    0.000    0.000 {method 'rfind' of 'str' objects}\n",
      "        2    0.000    0.000    0.000    0.000 dtypes.py:866(construct_from_string)\n",
      "        1    0.000    0.000    0.000    0.000 base.py:4377(equals)\n",
      "      110    0.000    0.000    0.000    0.000 peewee.py:729(unwrap)\n",
      "      110    0.000    0.000    0.000    0.000 peewee.py:726(is_alias)\n",
      "       45    0.000    0.000    0.000    0.000 __init__.py:2069(handle)\n",
      "        1    0.000    0.000    0.000    0.000 managers.py:935(_consolidate_inplace)\n",
      "        2    0.000    0.000    0.000    0.000 {built-in method builtins.round}\n",
      "        1    0.000    0.000    0.000    0.000 codecs.py:309(__init__)\n",
      "        1    0.000    0.000    0.000    0.000 traceback.py:145(_format_final_exc_line)\n",
      "       45    0.000    0.000    0.000    0.000 {method '__enter__' of '_thread.lock' objects}\n",
      "       11    0.000    0.000    0.000    0.000 peewee.py:2906(__enter__)\n",
      "       11    0.000    0.000    0.000    0.000 peewee.py:3112(is_closed)\n",
      "        6    0.000    0.000    0.000    0.000 __init__.py:187(_checkLevel)\n",
      "        2    0.000    0.000    0.000    0.000 pathlib.py:135(splitroot)\n",
      "        4    0.000    0.000    0.000    0.000 __init__.py:19(<genexpr>)\n",
      "        5    0.000    0.000    0.000    0.000 process.py:36(current_process)\n",
      "        1    0.000    0.000    0.000    0.000 {method 'view' of 'numpy.ndarray' objects}\n",
      "        2    0.000    0.000    0.000    0.000 common.py:1585(is_float_dtype)\n",
      "        1    0.000    0.000    0.000    0.000 codecs.py:186(__init__)\n",
      "        9    0.000    0.000    0.000    0.000 managers.py:169(<genexpr>)\n",
      "        1    0.000    0.000    0.000    0.000 ntpath.py:523(abspath)\n",
      "        5    0.000    0.000    0.000    0.000 threading.py:1052(name)\n",
      "        6    0.000    0.000    0.000    0.000 common.py:2020(pandas_dtype)\n",
      "        1    0.000    0.000    0.000    0.000 object.py:280(__post_init__)\n",
      "       10    0.000    0.000    0.000    0.000 common.py:211(<lambda>)\n",
      "        2    0.000    0.000    0.000    0.000 common.py:1063(is_unsigned_integer_dtype)\n",
      "        2    0.000    0.000    0.000    0.000 common.py:1850(_get_dtype)\n",
      "       11    0.000    0.000    0.000    0.000 {built-in method _functools.reduce}\n",
      "       10    0.000    0.000    0.000    0.000 common.py:209(classes)\n",
      "       45    0.000    0.000    0.000    0.000 {method 'release' of '_thread.lock' objects}\n",
      "        2    0.000    0.000    0.000    0.000 base.py:700(_reset_identity)\n",
      "        3    0.000    0.000    0.000    0.000 __init__.py:727(__init__)\n",
      "        2    0.000    0.000    0.000    0.000 utility.py:659(high)\n",
      "        1    0.000    0.000    0.000    0.000 common.py:230(dict_keys_to_ordered_list)\n",
      "        1    0.000    0.000    0.000    0.000 managers.py:655(<listcomp>)\n",
      "        2    0.000    0.000    0.000    0.000 {talib._ta_lib.RSI}\n",
      "       11    0.000    0.000    0.000    0.000 peewee.py:2098(__sql__)\n",
      "        1    0.000    0.000    0.000    0.000 base.py:681(is_)\n",
      "        2    0.000    0.000    0.000    0.000 inference.py:120(is_iterator)\n",
      "       11    0.000    0.000    0.000    0.000 peewee.py:2062(order_by)\n",
      "        6    0.000    0.000    0.000    0.000 {built-in method sys._getframe}\n",
      "       11    0.000    0.000    0.000    0.000 peewee.py:2907(__exit__)\n",
      "        6    0.000    0.000    0.000    0.000 traceback.py:302(walk_tb)\n",
      "        1    0.000    0.000    0.000    0.000 __init__.py:426(__init__)\n",
      "        2    0.000    0.000    0.000    0.000 pathlib.py:1001(_init)\n",
      "        8    0.000    0.000    0.000    0.000 {method 'values' of 'dict' objects}\n",
      "        1    0.000    0.000    0.000    0.000 traceback.py:528(_load_lines)\n",
      "        1    0.000    0.000    0.000    0.000 base.py:717(<lambda>)\n",
      "        5    0.000    0.000    0.000    0.000 base.py:5707(ensure_index)\n",
      "        1    0.000    0.000    0.000    0.000 {built-in method nt._getfullpathname}\n",
      "        1    0.000    0.000    0.000    0.000 construction.py:252(<listcomp>)\n",
      "        9    0.000    0.000    0.000    0.000 base.py:723(__len__)\n",
      "        2    0.000    0.000    0.000    0.000 __init__.py:863(setLevel)\n",
      "        2    0.000    0.000    0.000    0.000 {built-in method numpy.asarray}\n",
      "        1    0.000    0.000    0.000    0.000 <string>:1(__eq__)\n",
      "        1    0.000    0.000    0.000    0.000 managers.py:132(<listcomp>)\n",
      "        3    0.000    0.000    0.000    0.000 {method 'endswith' of 'str' objects}\n",
      "        5    0.000    0.000    0.000    0.000 {built-in method time.time}\n",
      "       11    0.000    0.000    0.000    0.000 {method 'close' of 'sqlite3.Cursor' objects}\n",
      "        4    0.000    0.000    0.000    0.000 common.py:214(classes_and_not_datetimelike)\n",
      "        1    0.000    0.000    0.000    0.000 template.py:412(load_bar)\n",
      "        1    0.000    0.000    0.000    0.000 codecs.py:260(__init__)\n",
      "        4    0.000    0.000    0.000    0.000 {method 'rpartition' of 'str' objects}\n",
      "        1    0.000    0.000    0.000    0.000 object.py:323(__post_init__)\n",
      "       12    0.000    0.000    0.000    0.000 {built-in method builtins.id}\n",
      "        1    0.000    0.000    0.000    0.000 {method 'startswith' of 'bytes' objects}\n",
      "        3    0.000    0.000    0.000    0.000 {method 'insert' of 'list' objects}\n",
      "        1    0.000    0.000    0.000    0.000 {built-in method builtins.sum}\n",
      "        2    0.000    0.000    0.000    0.000 __init__.py:232(_register_at_fork_acquire_release)\n",
      "        1    0.000    0.000    0.000    0.000 __init__.py:2075(createLock)\n",
      "        1    0.000    0.000    0.000    0.000 {method 'seek' of '_io.BufferedReader' objects}\n",
      "        1    0.000    0.000    0.000    0.000 {method 'decode' of 'bytes' objects}\n",
      "        1    0.000    0.000    0.000    0.000 _validators.py:231(validate_bool_kwarg)\n",
      "        1    0.000    0.000    0.000    0.000 managers.py:646(is_consolidated)\n",
      "        1    0.000    0.000    0.000    0.000 base.py:747(dtype)\n",
      "       10    0.000    0.000    0.000    0.000 {built-in method _thread.get_ident}\n",
      "        1    0.000    0.000    0.000    0.000 {method 'split' of 'str' objects}\n",
      "        1    0.000    0.000    0.000    0.000 managers.py:236(items)\n",
      "        2    0.000    0.000    0.000    0.000 template.py:439(put_event)\n",
      "        1    0.000    0.000    0.000    0.000 atr_rsi_strategy.py:136(on_trade)\n",
      "        1    0.000    0.000    0.000    0.000 construction.py:300(_homogenize)\n",
      "        5    0.000    0.000    0.000    0.000 {method 'rstrip' of 'str' objects}\n",
      "        4    0.000    0.000    0.000    0.000 common.py:219(<lambda>)\n",
      "        3    0.000    0.000    0.000    0.000 {method 'reverse' of 'list' objects}\n",
      "        4    0.000    0.000    0.000    0.000 utility.py:673(close)\n",
      "        1    0.000    0.000    0.000    0.000 managers.py:342(<genexpr>)\n",
      "        2    0.000    0.000    0.000    0.000 _dtype.py:307(_name_includes_bit_suffix)\n",
      "        1    0.000    0.000    0.000    0.000 construction.py:248(<genexpr>)\n",
      "        1    0.000    0.000    0.000    0.000 backtesting.py:1127(load_bar)\n",
      "        1    0.000    0.000    0.000    0.000 {method 'date' of 'datetime.datetime' objects}\n",
      "        2    0.000    0.000    0.000    0.000 __init__.py:910(setFormatter)\n",
      "        2    0.000    0.000    0.000    0.000 utility.py:666(low)\n",
      "        2    0.000    0.000    0.000    0.000 {method 'items' of 'dict' objects}\n",
      "        1    0.000    0.000    0.000    0.000 {built-in method sys.exc_info}\n",
      "        2    0.000    0.000    0.000    0.000 atr_rsi_strategy.py:130(on_order)\n",
      "        1    0.000    0.000    0.000    0.000 {method 'clear' of 'list' objects}\n",
      "        1    0.000    0.000    0.000    0.000 {pandas._libs.lib.is_bool}\n",
      "        1    0.000    0.000    0.000    0.000 construction.py:255(<listcomp>)\n",
      "        1    0.000    0.000    0.000    0.000 {method 'disable' of '_lsprof.Profiler' objects}\n",
      "\n",
      "\n"
     ]
    },
    {
     "ename": "KeyError",
     "evalue": "\"None of ['date'] are in the columns\"",
     "output_type": "error",
     "traceback": [
      "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m",
      "\u001b[1;31mKeyError\u001b[0m                                  Traceback (most recent call last)",
      "\u001b[1;32m~\\AppData\\Local\\Temp/ipykernel_8984/66826247.py\u001b[0m in \u001b[0;36m<module>\u001b[1;34m\u001b[0m\n\u001b[1;32m----> 1\u001b[1;33m \u001b[0mcProfile\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mrun\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;34m\"runBacktesting()\"\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0msort\u001b[0m\u001b[1;33m=\u001b[0m\u001b[1;34m\"cumulative\"\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m",
      "\u001b[1;32mc:\\vnstudio\\lib\\cProfile.py\u001b[0m in \u001b[0;36mrun\u001b[1;34m(statement, filename, sort)\u001b[0m\n\u001b[0;32m     14\u001b[0m \u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m     15\u001b[0m \u001b[1;32mdef\u001b[0m \u001b[0mrun\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mstatement\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mfilename\u001b[0m\u001b[1;33m=\u001b[0m\u001b[1;32mNone\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0msort\u001b[0m\u001b[1;33m=\u001b[0m\u001b[1;33m-\u001b[0m\u001b[1;36m1\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m---> 16\u001b[1;33m     \u001b[1;32mreturn\u001b[0m \u001b[0m_pyprofile\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0m_Utils\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mProfile\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mrun\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mstatement\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mfilename\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0msort\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[0;32m     17\u001b[0m \u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m     18\u001b[0m \u001b[1;32mdef\u001b[0m \u001b[0mrunctx\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mstatement\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mglobals\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mlocals\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mfilename\u001b[0m\u001b[1;33m=\u001b[0m\u001b[1;32mNone\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0msort\u001b[0m\u001b[1;33m=\u001b[0m\u001b[1;33m-\u001b[0m\u001b[1;36m1\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n",
      "\u001b[1;32mc:\\vnstudio\\lib\\profile.py\u001b[0m in \u001b[0;36mrun\u001b[1;34m(self, statement, filename, sort)\u001b[0m\n\u001b[0;32m     51\u001b[0m         \u001b[0mprof\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0mself\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mprofiler\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m     52\u001b[0m         \u001b[1;32mtry\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m---> 53\u001b[1;33m             \u001b[0mprof\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mrun\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mstatement\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[0;32m     54\u001b[0m         \u001b[1;32mexcept\u001b[0m \u001b[0mSystemExit\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m     55\u001b[0m             \u001b[1;32mpass\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n",
      "\u001b[1;32mc:\\vnstudio\\lib\\cProfile.py\u001b[0m in \u001b[0;36mrun\u001b[1;34m(self, cmd)\u001b[0m\n\u001b[0;32m     93\u001b[0m         \u001b[1;32mimport\u001b[0m \u001b[0m__main__\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m     94\u001b[0m         \u001b[0mdict\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0m__main__\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0m__dict__\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m---> 95\u001b[1;33m         \u001b[1;32mreturn\u001b[0m \u001b[0mself\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mrunctx\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mcmd\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mdict\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mdict\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[0;32m     96\u001b[0m \u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m     97\u001b[0m     \u001b[1;32mdef\u001b[0m \u001b[0mrunctx\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mself\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mcmd\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mglobals\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mlocals\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n",
      "\u001b[1;32mc:\\vnstudio\\lib\\cProfile.py\u001b[0m in \u001b[0;36mrunctx\u001b[1;34m(self, cmd, globals, locals)\u001b[0m\n\u001b[0;32m     98\u001b[0m         \u001b[0mself\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0menable\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m     99\u001b[0m         \u001b[1;32mtry\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m--> 100\u001b[1;33m             \u001b[0mexec\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mcmd\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mglobals\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mlocals\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[0;32m    101\u001b[0m         \u001b[1;32mfinally\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m    102\u001b[0m             \u001b[0mself\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mdisable\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n",
      "\u001b[1;32m<string>\u001b[0m in \u001b[0;36m<module>\u001b[1;34m\u001b[0m\n",
      "\u001b[1;32m~\\AppData\\Local\\Temp/ipykernel_8984/3726379257.py\u001b[0m in \u001b[0;36mrunBacktesting\u001b[1;34m()\u001b[0m\n\u001b[0;32m     15\u001b[0m     \u001b[0mengine\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mload_data\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m     16\u001b[0m     \u001b[0mengine\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mrun_backtesting\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m---> 17\u001b[1;33m     \u001b[0mengine\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mcalculate_result\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[0;32m     18\u001b[0m     \u001b[0mengine\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mcalculate_statistics\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m     19\u001b[0m     \u001b[0mengine\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mshow_chart\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n",
      "\u001b[1;32mc:\\vnstudio\\lib\\site-packages\\vnpy\\app\\cta_strategy\\backtesting.py\u001b[0m in \u001b[0;36mcalculate_result\u001b[1;34m(self)\u001b[0m\n\u001b[0;32m    437\u001b[0m         \u001b[0mpre_close\u001b[0m \u001b[1;33m=\u001b[0m \u001b[1;36m0\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m    438\u001b[0m         \u001b[0mstart_pos\u001b[0m \u001b[1;33m=\u001b[0m \u001b[1;36m0\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m--> 439\u001b[1;33m \u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[0;32m    440\u001b[0m         \u001b[1;32mfor\u001b[0m \u001b[0mdaily_result\u001b[0m \u001b[1;32min\u001b[0m \u001b[0mself\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mdaily_results\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mvalues\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m    441\u001b[0m \u001b[1;33m\u001b[0m\u001b[0m\n",
      "\u001b[1;32mc:\\vnstudio\\lib\\site-packages\\pandas\\core\\frame.py\u001b[0m in \u001b[0;36mset_index\u001b[1;34m(self, keys, drop, append, inplace, verify_integrity)\u001b[0m\n\u001b[0;32m   4409\u001b[0m                 \u001b[1;34m\"Cannot specify 'allow_duplicates=True' when \"\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m   4410\u001b[0m                 \u001b[1;34m\"'self.flags.allows_duplicate_labels' is False.\"\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m-> 4411\u001b[1;33m             )\n\u001b[0m\u001b[0;32m   4412\u001b[0m         \u001b[1;32mif\u001b[0m \u001b[1;32mnot\u001b[0m \u001b[0mallow_duplicates\u001b[0m \u001b[1;32mand\u001b[0m \u001b[0mcolumn\u001b[0m \u001b[1;32min\u001b[0m \u001b[0mself\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mcolumns\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m   4413\u001b[0m             \u001b[1;31m# Should this be a different kind of error??\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n",
      "\u001b[1;31mKeyError\u001b[0m: \"None of ['date'] are in the columns\""
     ]
    }
   ],
   "source": [
    "cProfile.run(\"runBacktesting()\", sort=\"cumulative\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "73dd3e15",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.7.1"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
